package org.nokatag.dbgrid;

import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.noka.gson.Gson;
import org.noka.gson.reflect.TypeToken;
import org.nokatag.system.ServletNokaContext;

/**
 * 接收并解析dbgrid编辑发回的请求
 * @author rebin
 *
 */
public class NDBGridRequest {
	
	
	/**
	 * <p>@Description 获取表格数据</p>
	 * <p>author rebin </p>
	 * <p>@Time 下午12:29:00</p>
	 * <p>xiefangjian@163.com</p>
	 * @return
	 */
	public static String getEditString(){
		return  getPars("nokardata");
	}
	/**
	 * <p>@Description 获取表格数据</p>
	 * <p>author rebin </p>
	 * <p>@Time 下午12:33:48</p>
	 * <p>xiefangjian@163.com</p>
	 * @return
	 */
	public static List<Map<String,String>> getEditListMap(){
		try{
			String editData = getPars("nokardata");
			Gson gson = new Gson();
			return gson.fromJson(editData,new TypeToken<List<Map<String,String>>>(){}.getType());
		}catch(Exception se){}
		return null;
	}
	/**
	 * <p>@Description 获取表格数据</p>
	 * <p>author rebin </p>
	 * <p>@Time 下午12:27:31</p>
	 * <p>xiefangjian@163.com</p>
	 * @param typeOfT
	 * @return
	 */
	public static <T> T  getEditData(Type typeOfT){
		try{
			String editData = getPars("nokardata");
			Gson gson = new Gson();
			return gson.fromJson(editData,typeOfT);
		}catch(Exception se){}
		return null;
	}
	
	/***
	 * <p>@Description 获取参数</p>
	 * <p>author rebin </p>
	 * <p>@Time 上午11:56:33</p>
	 * <p>xiefangjian@163.com</p>
	 * @param key
	 * @return
	 */
	private static String getPars(String key){
		HttpServletRequest request = ServletNokaContext.getRequest();
		return request.getParameter(key);
	}
}
